<!--
 Copyright 2025 Google LLC

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

    <div class="configure-title">
      <span>Configure new Playbook</span>
    </div>

  <div [formGroup]="this.intentForm">

    <mat-stepper [linear]="false" #stepper>
      <mat-step>
          <ng-template matStepLabel>Intent</ng-template>
          <div class="input-field-container">
            <mat-form-field
              class="intent-field"
              appearance="outline"
              [floatLabel]="'always'"
            >
              <mat-label>Name</mat-label>
              <input
                matInput
                [formControl]="this.intentForm.controls.name"
                placeholder="Intent name"
                type="text"
              />
            </mat-form-field>
            <mat-form-field
              class="intent-field"
              appearance="outline"
              [floatLabel]="'always'"
            >
              <mat-label>GCS Path to files</mat-label>
              <input
                matInput
                [formControl]="this.intentForm.controls.gcp_bucket"
                placeholder="gs://your-bucket/your-folder"
                type="text"
              />
            </mat-form-field>
          </div>
          <div class="button-container">
            <button mat-button class="submit-button" [disabled]="!this.intentForm.controls.name.valid || !this.intentForm.controls.gcp_bucket.valid" matStepperNext>Next</button>
          </div>
      </mat-step>
      <mat-step label="Fill out your address">
          <ng-template matStepLabel>AI Model</ng-template>
          <div class="input-field-container">
            <mat-form-field
              class="intent-field"
              appearance="outline"
              [floatLabel]="'always'"
            >
              <mat-label>AI Model</mat-label>
              <mat-select
                [formControl]="this.intentForm.controls.ai_model"
                placeholder="AI Model"
              >
                <mat-optgroup *ngFor="let model of this.models" [label]="model.name">
                  <mat-option
                    *ngFor="let model_name of model.models"
                    [value]="model_name"
                    >{{ model_name }}</mat-option
                  >
                </mat-optgroup>
              </mat-select>
            </mat-form-field>
            <div class="ai-temperature-field">
              <div class="ai-temperature-label-container">
                <label>Creativity</label>
                <label>{{ this.intentForm.controls.ai_temperature.value }}</label>
              </div>
              <mat-slider
                style="width: 100%"
                [max]="2"
                [min]="0"
                [step]="0.1"
                [discrete]="true"
                [showTickMarks]="true"
              >
                <input
                  matSliderThumb
                  class="slider"
                  [formControl]="this.intentForm.controls.ai_temperature"
                />
              </mat-slider>
            </div>
          </div>
          <div class="button-container">
            <button mat-button class="cancel-button" matStepperPrevious>Back</button>
            <button mat-button class="submit-button"
            [disabled]="!this.intentForm.controls.ai_model.valid || !this.intentForm.controls.ai_temperature.valid"
            matStepperNext>Next</button>
          </div>
      </mat-step>
      <mat-step>
        <ng-template matStepLabel>Prompt</ng-template>
        <div>
          <div class="input-field-container">
            <mat-form-field
              class="prompt-field"
              appearance="outline"
              [floatLabel]="'always'"
            >
              <mat-label>Prompt</mat-label>
              <textarea
                matInput
                [formControl]="this.intentForm.controls.prompt"
                placeholder="Enter Prompt here"
                rows="3"
                wrap="soft"
              >
              </textarea>
            </mat-form-field>
          </div>
        </div>
        <div class="button-container">
          <button mat-button class="cancel-button" matStepperPrevious>Back</button>
          <button mat-button class="submit-button"
          [disabled]="!this.intentForm.controls.prompt.valid"
          matStepperNext>Next</button>
        </div>
      </mat-step>
      <mat-step>
        <ng-template matStepLabel>Questions</ng-template>
        <div class="question-container">
          <mat-list>
            <mat-list-item
              class="questions-field-container"
              style="height: 100%"
              *ngFor="
                let control of this.intentForm.controls.questions.controls;
                let i = index
              "
            >
              <mat-form-field
                class="search-question-field"
                appearance="outline"
                [floatLabel]="'always'"
              >
                <input
                  matInput
                  placeholder="Enter a Question"
                  [formControl]="control"
                  type="text"
                />
                <mat-icon matSuffix (click)="removeQuestion(i)">delete</mat-icon>
              </mat-form-field>
            </mat-list-item>
          </mat-list>
        </div>
        <div class="button-container">
          <div>
            <button
            mat-button
            *ngIf="!this.showSpinner"
            class="add-question-button"
            (click)="addQuestion()"
          >
            Add Question
          </button>
          </div>
          <button mat-button
          *ngIf="!this.showSpinner"
          class="cancel-button" matStepperPrevious>Back</button>
          <button mat-button
          *ngIf="!this.showSpinner"
          class="submit-button" [disabled]="!this.intentForm.valid" (click)="saveForm()">Save</button>
          <div class="spinner-container" *ngIf="this.showSpinner">
            <mat-spinner style="width: 60px; height: 60px"></mat-spinner>
          </div>
        </div>
      </mat-step>
    </mat-stepper>
  </div>
